package 剑指offer.zw_62_圆圈中最后剩下的数字;

class Solution {
    public static void main(String[] args) {
        int n = lastRemaining(10, 17);
        System.out.println(n);
    }

    public static int lastRemaining(int n, int m) {
        return Remaining(n, m);
    }

    public static int Remaining(int n, int m) {
        if (n == 1) {
            return 0;
        }
        int x = Remaining(n - 1, m);
        return (m + x) % n;
    }


//    public static int lastRemaining(int n, int m) {
//        int f = 0;
//        for (int i = 2; i != n + 1; ++i) {
//            f = (m + f) % i;
//        }
//        return f;
//    }

}